/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package desktopapplication1;

import javax.swing.table.*;
import javax.swing.*;
import java.awt.Component;
import java.awt.Color;

public class CellRenderer extends DefaultTableCellRenderer
{
    int specRow, specCol;

    public CellRenderer()
    {
        specRow = -1;
        specCol = -1;
    }

    public Component getTableCellRendererComponent(JTable table,
                                                   Object value,
                                                   boolean isSelected,
                                                   boolean hasFocus,
                                                   int row, int col)
    {
        setHorizontalAlignment(JLabel.CENTER);

        Color color = Color.green;

        if (isSelected)
            color = Color.red;
        else
            color = Color.blue;

        if (hasFocus)
            color = Color.yellow;

        if(row == specRow && col == specCol)
            color = color.white;

        //setForeground(color);
        setBackground(color);
        setText((String)value);
        return this;
    }

    public void setSpecialSelection(int row, int col)
    {
        specRow = row;
        specCol = col;
    }
}